package com.lc.pianostudent.conn;

import com.lc.pianostudent.bean.PicarrBean;
import com.lc.pianostudent.bean.Post;
import com.lc.pianostudent.bean.User;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/2/22.
 */
@HttpInlet(Conn.CIRCLE_INDEX)
public class PostCircleIndex extends BaseAsyPost {

    public String user_id,type;
    public PostCircleIndex(AsyCallBack asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected PostCircleIndexInfo parser(JSONObject object) throws Exception {
        if (object.optString("code").equals("200")) {

            PostCircleIndexInfo info = new PostCircleIndexInfo();

            info.code = object.optString("code");
            JSONObject jsonObject = object.optJSONObject("user");
            info.num = jsonObject.optString("num");
            info.name = jsonObject.optString("name");
            info.person = jsonObject.optString("person");
            info.wealth = jsonObject.optString("wealth");
            info.degree = jsonObject.optString("degree");
            info.xuewei = jsonObject.optString("xuewei");
            info.grade = jsonObject.optString("grade");
            info.exper = jsonObject.optString("exper");
            info.cname = jsonObject.optString("cname");

            JSONArray array = object.optJSONArray("list");
            if(array != null || array.length() != 0){
                for(int i = 0;i<array.length();i++){
                    JSONObject o = array.optJSONObject(i);
                    User user = new User();
                    user.setAvatar(o.optString("avatar"));
                    user.setCname(o.optString("cname"));
                    user.setName(o.optString("name"));
                    user.setContent(o.optString("content"));
                    user.setId(o.optString("id"));
                    user.setUp(o.optString("up"));
                    user.setPosttype(o.optString("posttype"));
                    user.setTime(o.optString("time"));
                    user.setPostid(o.optString("postid"));
                    user.setCommentup(o.optBoolean("commentup"));

                    JSONArray array1 = o.optJSONArray("picarr");

                    if(array1.length() != 0){
                        for(int j = 0;j<array1.length();j++){
                            JSONObject jo = array1.optJSONObject(j);
                            String url = jo.optString("img");
                            info.picarrList.add(url);
                        }
                        user.setPicarr(info.picarrList);
                    }

                    info.userList.add(user);

                }


            }

            TOAST = object.optString("message");
            return info;

        } else {

            TOAST = object.optString("message");

        }

        return null;
    }

    public static class PostCircleIndexInfo {

        public String code,num,name,person,wealth,degree,xuewei,grade,exper,cname;

        public List<User> userList = new ArrayList<>();
        public List<String> picarrList = new ArrayList<>();

    }

}
